import {
    HYEventStore
} from 'hy-event-store'

import {
    getRankings
} from '../service/api_music'

const rankingStore = new HYEventStore({
    state: {
        hotRanking: {},
        newRanking: {},
        originRanking: {},
        upRanking: {}
    },
    actions: {
        getRankingDataAction(ctx) {
            //热歌榜：3778678 飙升榜：19723756 新歌榜：3779629 原创榜：2884035
            const ranks = [3778678, 19723756, 3779629, 2884035]
            for (let i = 0; i < ranks.length; i++) {
                let id = ranks[i]
                getRankings(id).then(res => {
                    switch (id) {
                        case 3778678:
                            ctx.hotRanking = res.playlist
                            break
                        case 19723756:
                            ctx.upRanking = res.playlist
                            break
                        case 3779629:
                            ctx.newRanking = res.playlist
                            break
                        case 2884035:
                            ctx.originRanking = res.playlist
                            break
                    }
                })
            }
            // getRankings(3778678).then(res => {
            //     //数据放入共享store
            //    ctx.hotRanking = res.playlist
            // })
        }
    }
})

export {
    rankingStore
}